package com.example.demo.smartLamp.controller;


import com.example.demo.common.ApiResponse;
import com.example.demo.smartLamp.entity.request.UserInfoGetRequest;
import com.example.demo.smartLamp.entity.request.UserLoginRequest;
import com.example.demo.smartLamp.entity.response.UserInfoGetResponse;
import com.example.demo.smartLamp.entity.response.UserLoginResponse;
import com.example.demo.smartLamp.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 祁荣博 胡绍宇
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/smartLamp/user")
@Api(tags = "User")
public class UserController {

    @Resource
    IUserService userService;

    @ApiOperation(value="获取用户信息")
    @PostMapping("/getInfo")
    public ApiResponse usergetInfo(
        @RequestBody UserInfoGetRequest userInfoGetRequest
    ) throws Exception {
        UserInfoGetResponse userInfoGetResponse = userService.userInfoGet(userInfoGetRequest);
        return ApiResponse.success(userInfoGetResponse);
    }


    @ApiOperation(value="用户登录")
    @PostMapping("/login")
    public ApiResponse usergetInfo(
            @RequestBody UserLoginRequest userLoginRequest
    ) throws Exception {
        UserLoginResponse userLoginResponse = userService.userLogin(userLoginRequest);
        return ApiResponse.success(userLoginResponse);
    }
}
